#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
智能客服系统 - 主程序入口
"""

import sys
import os

# 添加项目根目录到Python路径
project_root = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, project_root)
sys.path.insert(0, os.path.join(project_root, 'backend'))

print(f"项目根目录: {project_root}")
print(f"Python路径: {sys.path[0:2]}")

try:
    # 导入应用模块
    from backend.app import app
    
    if __name__ == '__main__':
        print("欢迎使用智能客服系统")
        print("正在启动服务...")
        try:
            # 直接运行Flask应用
            app.run(
                host='0.0.0.0',
                port=8000,
                debug=True
            )
        except KeyboardInterrupt:
            print("\n服务已被用户中断")
        except Exception as e:
            print(f"服务启动失败: {str(e)}")
            sys.exit(1)
except ImportError as e:
    print(f"导入错误: {str(e)}")
    sys.exit(1)